home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
9-Digit Zip Code Directory
/
9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO
/
z4src.zip
/
Z4SDFILE.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-22
|
7KB
|
192 lines
//----------------------------------------------------------------------------
// MODULE DESCRIPTION
//
// Module: z4sdfile.cpp
// Title: ZIP+4 Engine
// Notice: John M. Weeder
// Copyright (c) 1993. All rights reserved.
// This module contains proprietary information and should be
// treated as confidential.
//
//----------------------------------------------------------------------------
// MAINTENANCE HISTORY
//
// $Workfile$
// $Revision$
// $Author$
// $Date$
// $Log$
//
//----------------------------------------------------------------------------
// MODULE NARRATIVE
//
// This module contains code for the class Z4_SD_FILE.
//
// The code in this module may be written in C++ or C.
//
// This module is portable to:
// DOS 3.X+
// MS Windows 3.X+
// OS/2 2.X+
// OS/2 2.0 PM
//
// The following compilers are supported:
// MSC 6.0A
// MSC/C++ 7.0
// Borland C++ 3.1 for DOS
// Borland C++ 1.0 for OS/2 2.X
//
//----------------------------------------------------------------------------
#include <z4.h>
//----------------------------------------------------------------------------
// Description: Default constructor
// Parameters: state State to get detail information for.
// Returns:
//----------------------------------------------------------------------------
FN_M Z4_SD_FILE::Z4_SD_FILE(Z4_STATE state)
{
Z4_SD_FILE::Initialize(CL_INIT_CLASS);
if (state != Z4_ST_INVALID)
Get(state);
}
//----------------------------------------------------------------------------
// Description: Copy constructor
// Parameters: rcz4_st_file Reference to object to copy.
// Returns:
//----------------------------------------------------------------------------
FN_M Z4_SD_FILE::Z4_SD_FILE(RCZ4_SD_FILE rcz4_st_file)
{
Z4_SD_FILE::Initialize(CL_INIT_CLASS);
*this = rcz4_st_file;
}
//----------------------------------------------------------------------------
// Description: Destructor
// Parameters:
// Returns:
//----------------------------------------------------------------------------
FN_M Z4_SD_FILE::~Z4_SD_FILE()
{
Z4_SD_FILE::Destroy(FALSE);
}
//----------------------------------------------------------------------------
// Description: Destroy object. Free any resources used by object.
// Normally called by destructor.
// Should allow multiple calls from various classes.
// A class should almost always re-init its variables when
// it is destroyed to prevent accidents.
// Parameters: fDestroyAll Destroy parents also?
// Default is TRUE.
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_M Z4_SD_FILE::Destroy(BOOL fDestroyAll)
{
if (pchCounties)
MemFree(pchCounties);
Z4_SD_FILE::Initialize(CL_INIT_CLASS_VARS);
if (fDestroyAll) // Destroy parent.
Z4_SD_FILE_PARENT::Destroy(fDestroyAll);
return TRUE;
}
//----------------------------------------------------------------------------
// Description: Get detail information for a state.
// Parameters: state State to get detail information for.
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_M Z4_SD_FILE::Get(Z4_STATE state)
{
Assert(state >= Z4_ST_FIRST && state <= Z4_ST_LAST);
Destroy(); // Destroy current state detail info
// No state info?
PCSZ pszState = Z4_ST_FILE::Abbreviation(state);
if (!DioIsLogicalFile(pszState, DFT_RANDOM))
return FALSE;
HLF hlf; // Load information
if (!DioOpenLogical(pszState, &hlf, DFT_RANDOM))
return SetError();
if (!DioRead(hlf, (PBYTE)&sd, sizeof(sd), NULL))
goto ERROR_EXIT;
pchCounties = (PCHAR)MemAlloc((SIZET)sd.cbCounties);
if (pchCounties == NULL)
goto ERROR_EXIT;
if (!DioRead(hlf, (PBYTE)pchCounties, (SIZET)sd.cbCounties, NULL))
goto ERROR_EXIT;
if (!DioCloseLogical(hlf))
goto ERROR_EXIT;
fValid = TRUE;
return TRUE;
ERROR_EXIT:
DioCloseLogical(hlf);
return SetError();
}
//----------------------------------------------------------------------------
// Description: Initialize object.
// Normally called by constructor.
// Should allow multiple calls from various classes.
// Parameters: sInit Initialization code. May be one of the following:
// CL_INIT_CLASS Reset class variables and
// and dynamic allocations for
// this class only.
// CL_INIT_CLASS_VARS Reset class variables for
// this class only.
// CL_INIT_VARS Reset class variables for
// this class only.
// CL_INIT_ALL Initialize class and all
// parent class, including
// dynamic memory allocation.
// Default is CL_INIT_ALL
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_M Z4_SD_FILE::Initialize(SHORT sInit)
{
if (sInit == CL_INIT_VARS || sInit == CL_INIT_ALL)
Z4_SD_FILE_PARENT::Initialize(sInit);
memset(&sd, 0, sizeof(sd));
pchCounties = NULL;
fValid = FALSE;
return TRUE;
}
//----------------------------------------------------------------------------
// Description: Check if object is valid
// IsValid() && IsError() MUST NOT BE DEPENDENT ON ONE ANOTHER.
// Parameters:
// Returns: TRUE if valid
//----------------------------------------------------------------------------
BOOL FN_M Z4_SD_FILE::IsValid() const
{
return Z4_SD_FILE_PARENT::IsValid() && fValid;
}
//----------------------------------------------------------------------------
// Description: Assignment operator
// NOTE: Don't copy object into self
// Parameters: rcz4_st_file Reference to right value.
// Returns: Reference to new object.
//----------------------------------------------------------------------------
RCZ4_SD_FILE FN_M Z4_SD_FILE::operator=(RCZ4_SD_FILE rcz4_st_file)
{
if (this != &rcz4_st_file)
{
Invalid("Z4_SD_FILE::operator=");
}
return (RCZ4_SD_FILE)*this;
}
//----------------------------------------------------------------------------
//------------------------------- End of File --------------------------------
//----------------------------------------------------------------------------